__________________________________________________________________________________________________
class Solution(object):
    memo = {(0, 0): 0}
    queue = [(0, 0, 0)]
    for x, y, d in queue:
        for dx, dy in ((2, -1), (2, 1), (-2, -1), (-2, 1), (1, -2), (1, 2), (-1, -2), (-1, 2)):
            nx = x+dx
            ny = y+dy
            if -5 <= nx <= 302 and -5 <= ny <= 302:
                if (nx, ny) not in memo:
                    memo[nx,ny] = d+1
                    queue.append((nx, ny, d+1))
       
    def minKnightMoves(self, x, y):
        x = abs(x)
        y = abs(y)
        return Solution.memo[x,y]
__________________________________________________________________________________________________

__________________________________________________________________________________________________
